package io.github.liuqun.sandbox;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

import static io.github.liuqun.sandbox.common.DesensitizationUtils.tokenDesensitize;

public class MinioConnectionConfiguration {
    private static final String DEFAULT_ACCESS_USER_NAME = "minioadmin";
    private static final String DEFAULT_SECRET_KEY = "minioadmin";

    private String accessKey = DEFAULT_ACCESS_USER_NAME;
    private String secretKey = DEFAULT_SECRET_KEY;

    private Endpoint endpoint;

    // TCP握手阶段最大等待时长, 一般为ms毫秒级
    private Duration maxConnectTimeout = Duration.of(500, ChronoUnit.MILLIS);

    // 业务数据读写收发允许等待若干秒甚至几分钟
    private Duration maxReadTimeout = Duration.of(10, ChronoUnit.SECONDS);
    private Duration maxWriteTimeout = Duration.of(10, ChronoUnit.SECONDS);

    @Override
    public String toString() {
        /// 调试日志禁止打印明文密码, 改为使用***隐藏真实密码
        String maskedUserName = tokenDesensitize(accessKey);
        String maskedPassword = tokenDesensitize(secretKey);
        return "MinioClientSdkConfigProperties{" +
                "endpoint=" + endpoint +
                ", accessKey='" + maskedUserName + '\'' +
                ", secretKey='" + maskedPassword + '\'' +
                ", maxConnectTimeout=" + maxConnectTimeout +
                ", maxReadTimeout=" + maxReadTimeout +
                ", maxWriteTimeout=" + maxWriteTimeout +
                '}';
    }

    public static class Endpoint {
        /**
         * MinIO 服务器地址, 可以用域名或数字IPv4地址
         */
        private String host;

        // 端口号
        private Short port = 9000;
        private Boolean useHttps = false;

        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public Short getPort() {
            return port;
        }

        public void setPort(Short port) {
            this.port = port;
        }

        public Boolean getUseHttps() {
            return useHttps;
        }

        public void setUseHttps(Boolean useHttps) {
            this.useHttps = useHttps;
        }
    }

    public Endpoint getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(Endpoint endpoint) {
        this.endpoint = endpoint;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public Duration getMaxConnectTimeout() {
        return maxConnectTimeout;
    }

    public void setMaxConnectTimeout(Duration maxConnectTimeout) {
        this.maxConnectTimeout = maxConnectTimeout;
    }

    public Duration getMaxReadTimeout() {
        return maxReadTimeout;
    }

    public void setMaxReadTimeout(Duration maxReadTimeout) {
        this.maxReadTimeout = maxReadTimeout;
    }

    public Duration getMaxWriteTimeout() {
        return maxWriteTimeout;
    }

    public void setMaxWriteTimeout(Duration maxWriteTimeout) {
        this.maxWriteTimeout = maxWriteTimeout;
    }
}
